package com.xihuanjun.util.json;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class JsonResult implements Serializable {

    public static final String KEY_ITEM="item";
    public static final String KEY_ITEMS="items";
    public static final String KEY_PAGE="pagedata";
    public static final String KEY_TOKEN1="token";
    public static final String KEY_TOKEN2="refToken";

    //是否成功
    private Boolean success;

    //返回码
    private Integer code;

    //返回消息
    private String message;

    //返回数据
    private Map<String, Object> data = new HashMap<String, Object>();

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    public JsonResult(){}

    public JsonResult succ(boolean success){
        this.success=success;
        return this;
    }

    public JsonResult msg(String msg){
        this.message=msg;
        return this;
    }

    public JsonResult code(Integer code){
        this.code=code;
        return this;
    }

    public JsonResult data(String key , Object value){
        this.data.put(key,value);
        return this;
    }


    public JsonResult map(Map map){
        Iterator iterator = map.keySet().iterator();
        while(iterator.hasNext()){
            String key = iterator.next().toString();
            this.data.put(key,map.get(key));
        }
        return this;
    }
}